home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 9.4 KB | 383 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWGC.cpp
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWGC_H
- #include "FWGC.h"
- #endif
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- #ifndef FWINK_H
- #include "FWInk.h"
- #endif
-
- #ifndef FWSTYLE_H
- #include "FWStyle.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _FACET_
- #include <Facet.h>
- #endif
-
- #ifndef _SHAPE_
- #include <Shape.h>
- #endif
-
- #ifndef _WINDOW_
- #include <Window.h>
- #endif
-
- #ifndef _PLFMTYPE_
- #include <PltmType.h>
- #endif
-
- #ifndef _TRNSFORM_
- #include <Trnsform.h>
- #endif
-
- #ifndef _CANVAS_
- #include <Canvas.h>
- #endif
-
- #ifndef _CANVAS_
- #include <Canvas.h>
- #endif
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__TOOLUTILS__)
- #include <ToolUtils.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__FIXMATH__)
- #include <FixMath.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
- #include <math routines.h>
- #endif
-
- //==============================================================================
- // •• RunTime Info
- //==============================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgraphx
- #endif
-
- //==============================================================================
- // •• class FW_CGraphicContext
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // • FW_CGraphicContext::FW_CGraphicContext
- //------------------------------------------------------------------------------
-
- FW_CGraphicContext::FW_CGraphicContext(XMPFacet *xmpFacet, XMPShape* clipShape) :
- fWindowFocus(FALSE),
- fXMPFacet(xmpFacet),
- fXMPCanvas(xmpFacet->GetCanvas()),
- fInkSeed(0),
- fStyleSeed(0),
- fForceSelect(FALSE),
- fPreviousGraphicContext(gGraphicGlobales.gLastGC)
- {
- #ifdef FW_BUILD_MAC
- ::GetPort(&fPreviousPort);
-
- ::SetPort(fXMPCanvas->GetPlatformCanvas());
-
- fCurOrigin.h = XMPASLMQDGlobals.thePort->portRect.left;
- fCurOrigin.v = XMPASLMQDGlobals.thePort->portRect.top;
-
- fOldClip = NewRgn();
- ::GetClip(fOldClip);
-
- ::SetClip(clipShape ? clipShape->GetQDRegion() : fXMPFacet->GetAggregateClipShape()->GetQDRegion());
-
- FW_CPoint offset(0,0);
- offset = fXMPFacet->GetContentTransform()->TransformPoint(offset);
- ::SetOrigin(-(offset.IntX()), -(offset.IntY()));
- #endif
-
- #ifdef FW_BUILD_WIN
- #endif
-
- gGraphicGlobales.gLastGC = this;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CGraphicContext::FW_CGraphicContext
- //------------------------------------------------------------------------------
-
- FW_CGraphicContext::FW_CGraphicContext(XMPWindow* xmpWindow) :
- fWindowFocus(TRUE),
- fXMPFacet(xmpWindow->GetRootFacet()),
- fXMPCanvas(fXMPFacet->GetCanvas()),
- fInkSeed(0),
- fStyleSeed(0),
- fForceSelect(FALSE),
- fPreviousGraphicContext(gGraphicGlobales.gLastGC)
- {
-
- #ifdef FW_BUILD_MAC
- ::GetPort(&fPreviousPort);
-
- ::SetPort(fXMPCanvas->GetPlatformCanvas());
-
- fCurOrigin.h = XMPASLMQDGlobals.thePort->portRect.left;
- fCurOrigin.v = XMPASLMQDGlobals.thePort->portRect.top;
-
- fOldClip = ::NewRgn();
- ::GetClip(fOldClip);
-
- ::SetOrigin(0, 0);
-
- ::ClipRect(&XMPASLMQDGlobals.thePort->portRect);
- #endif
-
- #ifdef FW_BUILD_WIN
- #endif
-
- gGraphicGlobales.gLastGC = this;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CGraphicContext::~FW_CGraphicContext
- //------------------------------------------------------------------------------
-
- FW_CGraphicContext::~FW_CGraphicContext()
- {
- InvalidPreviousGCCache(); // Force selection of the previous gc with the same canvas
-
- #ifdef FW_BUILD_MAC
- // ----- Restore previous grafport and origin -----
- ::SetOrigin(fCurOrigin.h, fCurOrigin.v);
- ::SetClip(fOldClip);
- ::DisposeRgn(fOldClip);
- fOldClip = NULL;
-
- ::PenNormal();
- ::RGBForeColor(&FW_kRGBBlack);
- ::RGBBackColor(&FW_kRGBWhite);
-
- ::SetPort(fPreviousPort);
- #endif
-
- #ifdef FW_BUILD_WIN
- #endif
-
- gGraphicGlobales.gLastGC = fPreviousGraphicContext;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CGraphicContext::AsPlatformPoint
- //------------------------------------------------------------------------------
-
- FW_SPlatformPoint FW_CGraphicContext::AsPlatformPoint(const FW_CPoint& point)
- {
- FW_SPlatformPoint pt;
-
- #ifdef FW_BUILD_MAC
- pt.h = FixedToInt(point.x);
- pt.v = FixedToInt(point.y);
- #endif
-
- #ifdef FW_BUILD_MAC
- #endif
-
- return pt;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CGraphicContext::AsPlatformRect
- //------------------------------------------------------------------------------
-
- FW_SPlatformRect FW_CGraphicContext::AsPlatformRect(const FW_CRect& rect)
- {
- FW_SPlatformRect r;
-
- #ifdef FW_BUILD_MAC
- ::SetRect(&r, FixedToInt(rect.left), FixedToInt(rect.top), FixedToInt(rect.right), FixedToInt(rect.bottom));
- #endif
-
- #ifdef FW_BUILD_WIN
- #endif
-
- return r;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CGraphicContext::AsPlatformRegion
- //------------------------------------------------------------------------------
-
- FW_PlatformRegion FW_CGraphicContext::AsPlatformRegion(XMPShape* shape)
- {
- #ifdef FW_BUILD_MAC
- return shape->GetQDRegion();
- #endif
- #ifdef FW_BUILD_WIN
- #endif
- }
-
- //------------------------------------------------------------------------------
- // • FW_CGraphicContext::GetClipShape
- //------------------------------------------------------------------------------
-
- void FW_CGraphicContext::GetClipShape(XMPShape* clipShape)
- {
- #ifdef FW_BUILD_MAC
- XMPRgnHandle clip = ::NewRgn();
- ::GetClip(clip);
- clipShape->SetQDRegion(clip);
- #endif
- #ifdef FW_BUILD_WIN
- #endif
- }
-
- //------------------------------------------------------------------------------
- // • FW_CGraphicContext::SetClipShape
- //------------------------------------------------------------------------------
- // SetClipShape uses a copy of the shape
-
- void FW_CGraphicContext::SetClipShape(XMPShape* clipShape)
- {
- #ifdef FW_BUILD_MAC
- ::SetClip(clipShape->GetQDRegion());
- #endif
-
- #ifdef FW_BUILD_MAC
- #endif
- }
-
- //------------------------------------------------------------------------------
- // • FW_CGraphicContext::InvalidPreviousGCCache
- //------------------------------------------------------------------------------
- // Look for a previous FW_CGraphicContext with the same canvas and set its
- // fForceSelect flag to true.
-
- void FW_CGraphicContext::InvalidPreviousGCCache()
- {
- FW_CGraphicContext* gc = fPreviousGraphicContext;
-
- while (gc != NULL)
- {
- if (gc->GetCanvas() == fXMPCanvas)
- {
- gc->fForceSelect = TRUE;
- return;
- }
-
- gc = gc->fPreviousGraphicContext;
- }
- }
-
- //------------------------------------------------------------------------------
- // • FW_CGraphicContext::SyncGraphicContext
- //------------------------------------------------------------------------------
-
- void FW_CGraphicContext::SyncGraphicContext(XMPShape* clipShape)
- {
- #ifdef FW_BUILD_MAC
- ::SetPort(fXMPCanvas->GetPlatformCanvas());
-
- if (clipShape)
- {
- ::SetClip(clipShape->GetQDRegion());
- }
- else
- {
- if (fWindowFocus)
- ::ClipRect(&XMPASLMQDGlobals.thePort->portRect);
- else
- ::SetClip(fXMPFacet->GetAggregateClipShape()->GetQDRegion());
- }
-
- FW_CPoint offset(0,0);
-
- if (!fWindowFocus)
- offset = fXMPFacet->GetContentTransform()->TransformPoint(offset);
-
- ::SetOrigin(-(offset.IntX()), -(offset.IntY()));
-
- ::PenNormal();
-
- fForceSelect = TRUE;
- #endif
- }
-
- #ifdef FW_BUILD_MAC
- //------------------------------------------------------------------------------
- // • FW_CGraphicContext::SelectInkAndStyle
- //------------------------------------------------------------------------------
-
- void FW_CGraphicContext::SelectInkAndStyle(FW_CInk ink, FW_CStyle style, FW_ShapeCategory shapeCategory, FW_ShapeFills shapeFill)
- {
- FW_UNUSED(shapeFill);
-
- WASSERTM((const void*)ink != NULL, "Can't select a null ink");
- WASSERTM((const void*)style != NULL, "Can't select a null style");
-
- if (fForceSelect || ink->GetSeed() != fInkSeed || fShapeCategory != shapeCategory)
- {
- fInkSeed = ink->GetSeed();
- fShapeCategory = shapeCategory;
- ink->SelectInGC(this, shapeCategory);
- }
-
- if (fForceSelect || style->GetSeed() != fStyleSeed || fShapeCategory != shapeCategory)
- {
- fStyleSeed = style->GetSeed();
- fShapeCategory = shapeCategory;
- style->SelectInGC(this, shapeCategory);
- }
-
- fForceSelect = FALSE;
- }
-
- #endif
-
- #ifdef FW_BUILD_WIN
- //------------------------------------------------------------------------------
- // • FW_CGraphicContext::SelectInkAndStyle
- //------------------------------------------------------------------------------
-
- void FW_CGraphicContext::SelectInkAndStyle(FW_CInk ink, FW_CStyle style, FW_ShapeCategory shapeCategory, FW_ShapeFills shapeFill)
- {
- WASSERTM((const void*)ink != NULL, "Can't select a null ink");
- WASSERTM((const void*)style != NULL, "Can't select a null style");
-
- if (fForceSelect || ink->GetSeed() != fInkSeed || fInkShapeCategory != shapeCategory)
- {
- fInkSeed = ink->GetSeed();
- fInkShapeCategory = shapeCategory;
- ink->SelectInGC(this, shapeCategory);
- }
-
- if (fForceSelect || style->GetSeed() != fStyleSeed || fStyleShapeCategory != shapeCategory)
- {
- fStyleSeed = style->GetSeed();
- fStyleShapeCategory = shapeCategory;
- style->SelectInGC(this, shapeCategory);
- }
-
- fForceSelect = FALSE;
- }
- #endif
-